﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Common
{
    /// <summary>
    /// Defines an interface that is implemented by classes
    /// that can draw visual representation of the data.
    /// </summary>
    interface IStatisticsDrawer
    {
        void DrawData(DrawContext g, List<DataRow> items);
    }

    public class DrawContext
    {
        private Point _location;
        private Graphics _graphics;
        private int _height;
        private int _width;
        private double _maxValue;

        public DrawContext(Point location, Graphics g, int width, int height, double maxValue)
        {
            _location = location;
            _graphics = g;
            _width = width;
            _height = height;
            _maxValue = maxValue;
        }

        public void DrawLine(Pen pen, Point point1, Point point2)
        {
            point1.Y = (_location.Y - point1.Y);
            point1.X += (_location.X);
            point2.Y = (_location.Y - point2.Y);
            point2.X += (_location.X);
            _graphics.DrawLine(pen, point1, point2);
        }

        /// <summary>
        /// Convert the specifiesd value to pixels on the screen. The value can be in range from 0 to MaxValue
        /// </summary>
        public int ToPixels(double value)
        {
            return (int)(_height / (_maxValue / value));
        }

        public int Width { get { return _width; } }
        public int Height { get { return _height; } }
    }
}
